package com.margo.rabbit.springboot;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  https://www.cnblogs.com/MagicAsa/p/10826596.html
 * 		RabbitMQ代码操作之发消息和序列化机制
 * 1.RabbitAutoConfiguration
 * 2.有自动配置了连接工厂 ConnectionFactory
 * 3.RabbitProperties 封装了RabbitMQ的配置
 * 4.RabiitTemlate：给RabbitMQ发送和接收消息
 * 5.AmqpAdmin：RabbitMQ系统管理功能组件（可以创建exchange,queue,Binding）
 * 6.@EnableRabbit+@RabbitListener 监听消息队列的内容
 * 
 * @author fangxingbang
 *
 */
@Configuration
public class RabbitConfig {
	 @Bean
     public Queue firstQueue() {
       // 创建一个队列，名称为：enjoy
        return new Queue("margo-queue",false);
     }
	 
	 //如果没有创建队列 ,启动消费者reply-code=404, reply-text=NOT_FOUND - no queue 'margo-direct' in vhost '/'
	 @Bean
     public Queue margoDirectQueue() {
       // 创建一个队列，名称为：enjoy
        return new Queue("margo-direct",false);
     }
	 
	 @Bean
	 public MessageConverter messageConverter(){
		 return new Jackson2JsonMessageConverter();
	 }
}
